package com.xzy.d;

import com.xzy.service.BookService;
import com.xzy.service.CourseService;
import com.xzy.service.SchoolService;
import com.xzy.service.TeacherService;
import lombok.extern.slf4j.Slf4j;

/**
 * 自动依赖注入的方式：<bean autowire="constructor"/> + 构造方法
 *
 * @author xzy
 * @date 2021/12/711:39
 */
@Slf4j
public class ConsServiceImpl {
    private BookService bookService;
    private CourseService courseService;
    private SchoolService schoolService;
    private TeacherService teacherService;

    /*
     * <bean autowire="constructor"/> + 构造方法 ：
     *     1.遍历Bean的构造方法：参数列表长的先遍历
     *     2.根据参数列表中参数的类型到Spring容器中寻找Bean
     *         如果每个参数都能找到唯一的Bean，那么调用当前构造方法完成依赖注入，
     *         否则跳过当前构造方法，检查下一个构造方法，直到无参构造方法（如果没有无参构造方法则抛出异常）
     */

    public ConsServiceImpl() {
        log.info("实例化 => ConsServiceImpl()");
    }

    public ConsServiceImpl(BookService bookService) {
        this.bookService = bookService;
        log.info("实例化 => \n\tConsServiceImpl(\n\t\t{}\n\t)", bookService);
    }

    public ConsServiceImpl(BookService bookService, CourseService courseService) {
        this.bookService = bookService;
        this.courseService = courseService;
        log.info("实例化 => \n\tConsServiceImpl(\n\t\t{},\n\t\t{}\n\t)", bookService, courseService);
    }

    public ConsServiceImpl(BookService bookService, CourseService courseService, SchoolService schoolService) {
        this.bookService = bookService;
        this.courseService = courseService;
        this.schoolService = schoolService;
        log.info("实例化 => \n\tConsServiceImpl(\n\t\t{},\n\t\t{},\n\t\t{}\n\t)", bookService, courseService, schoolService);
    }

    public ConsServiceImpl(BookService book, CourseService course, SchoolService school, TeacherService teacher) {
        this.bookService = book;
        this.courseService = course;
        this.schoolService = school;
        this.teacherService = teacher;
        log.info("实例化 => \n\tConsServiceImpl(\n\t\t{},\n\t\t{},\n\t\t{},\n\t\t{}\n\t)", book, course, school, teacher);
    }
}
